<?php

namespace App\Services\ApplySeckillProductBatchPay;

use App\Models\User;
use App\Jobs\ApplyOrderPayingJob;

class ApplySeckillPorductBatchPay
{
	protected User $user;

	protected array $unpaidCacheIds = [];

	public function __construct(User $user, $unpaidCacheIds)
	{
		$this->user = $user;
		$this->unpaidCacheIds = $unpaidCacheIds;
	}

	public function pay()
	{
		if (count($this->unpaidCacheIds) <= 0) return;

		
		foreach ($this->unpaidCacheIds as $cacheId) {
            $this->user->markOrderPayCachePaying($cacheId);
		}
		$queue = app()->environment('local') ? 'default' : 'pay_seckill_order';
		dispatch(new ApplyOrderPayingJob($this->user, $this->unpaidCacheIds))->onQueue($queue);
	}
}
